#!/bin/bash
# Copyright (C) 2016-2020 eGloo, Incorporated
#
# This is free software, licensed under the GNU General Public License v3.

# @PACKAGE_TARNAME@	Start up the @PACKAGE_NAME@
#
# chkconfig: 2345 55 25
# description: @PACKAGE_NAME@
#
# processname: @PACKAGE_TARNAME@
# config: @sysconfdir@/@PACKAGE_TARNAME@.conf
# pidfile: @volatilestatedir@/@PACKAGE_TARNAME@.pid

### BEGIN INIT INFO
# Provides: @PACKAGE_TARNAME@
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the @PACKAGE_NAME@
# Description: @PACKAGE_NAME@
### END INIT INFO

# Source function library.
. /etc/init.d/functions

RETVAL=0
prog="@PACKAGE_TARNAME@"
PID_FILE=@volatilestatedir@/@PACKAGE_TARNAME@.pid

start() {
    # Load defaults.
    if [ -f @datadir@/functions.sh ]; then
        source @datadir@/functions.sh

        NETIFYD_OPTS=$(auto_detect_options)

        load_modules
    fi

    echo -n "Starting $prog: "

    daemon $prog $NETIFYD_OPTS
    success
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    echo
    return $RETVAL
}

stop() {
    echo -n "Shutting down $prog: "
    killproc $prog
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    echo
    return $RETVAL
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    status)
        $prog --status
        status $prog
    ;;
    restart)
        stop
        start
    ;;
    condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
            RETVAL=$?
        fi
    ;;
    *)
    echo "Usage: $prog {start|stop|status|restart|condrestart}"
    exit 1
    ;;
esac
exit $RETVAL

# vi: expandtab shiftwidth=4 softtabstop=4 tabstop=4 syntax=sh
